import {
	common
} from "./common.js"
import hexMD5 from "./md5.js"
import uQRCode from "./uqrcode.js"
console.log(uQRCode)
export const plugins = {
	dateFormate(d, pattern) {
		d = d ? new Date(d) : new Date();
		pattern = pattern || "yyyy-MM-dd";
		var y = d.getFullYear().toString(),
			o = {
				M: d.getMonth() + 1,
				d: d.getDate(),
				h: d.getHours(),
				m: d.getMinutes(),
				s: d.getSeconds(),
			};
		pattern = pattern.replace(/(y+)/gi, function(a, b) {
			return y.substr(4 - Math.min(4, b.length));
		});
		for (var i in o) {
			pattern = pattern.replace(new RegExp("(" + i + "+)", "g"), function(
				a,
				b
			) {
				return o[i] < 10 && b.length > 1 ? "0" + o[i] : o[i];
			});
		}
		return pattern;
	},
	requstData(that, func, v) {
		return new Promise((resolve, reject) => {
			const funs = [...func],
				promiseAlls = [];
			funs.forEach(name => {
				promiseAlls.push(that.$store.dispatch(name, v));
			});
			Promise.all(promiseAlls)
				.then(v => {
					resolve(v);
				})
				.catch(v => {
					reject(v);
				})
				.finally(v=>{
					setTimeout(() => {
						uni.hideLoading();
						uni.stopPullDownRefresh()
					}, 1000);
				});
		});
	},
	...common,
	...hexMD5,
	...{uQRCode:uQRCode},
	formatCount(v) {
		let a = v,
			n = 0;
		for (let i = a.length - 1; i >= 0; i--) {
			n += 1;
			if (n === 3) {
				let b = v.split('');
				b.splice(i, 0, ',');
				v = b.join('');
				n = 0;
			}
		}
		return v;
	}
}
